package com.yanqu.road.dao.impl.activity.hanghai;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.hanghai.config.HangHaiPortConfig;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class HangHaiPortConfigDaoImpl extends TempDao {

    public static String getHangHaiPortConfigMapSql = "select * from t_s_activity_hanghai_port where activityId=?";

    public Map<Integer, HangHaiPortConfig> getHangHaiPortConfigMap(int activityId) {
        Map<Integer, HangHaiPortConfig> map = new ConcurrentHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getHangHaiPortConfigMapSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                HangHaiPortConfig hangHaiPortConfig = new HangHaiPortConfig();
                hangHaiPortConfig.setActivityId(rs.getInt("activityId"));
                hangHaiPortConfig.setPortId(rs.getInt("portId"));
                hangHaiPortConfig.setName(rs.getString("name"));
                hangHaiPortConfig.setDesc(rs.getString("desc"));
                hangHaiPortConfig.setIcon(rs.getString("icon"));
                hangHaiPortConfig.setPlaceCoordinate(rs.getString("placeCoordinate"));
                hangHaiPortConfig.setSpecGoodsId(rs.getInt("specGoodsId"));
                map.put(hangHaiPortConfig.getPortId(), hangHaiPortConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

}
